package top.hcode.hoj.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.hcode.hoj.common.result.CommonResult;
import top.hcode.hoj.pojo.dto.BaseIdDTO;
import top.hcode.hoj.pojo.dto.coll.AdmCollQuestionJsonImportDTO;
import top.hcode.hoj.pojo.entity.coll.CollQuestion;
import top.hcode.hoj.pojo.form.AdmCollGetQuestionForm;
import top.hcode.hoj.pojo.form.AdmQueryCollQuestionForm;
import top.hcode.hoj.service.admin.AdminCollQuestionService;

/**
 * @author orangej
 * @since 2025-02-09
 */
@Slf4j
@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
public class AdminCollQuestionController {

    private final AdminCollQuestionService questionService;

    @GetMapping("/admin/coll-question/list")
    public CommonResult<IPage<CollQuestion>> getCollQuestionList(AdmQueryCollQuestionForm form) {
        return CommonResult.successResponse(questionService.getCollQuestionList(form));
    }

    @GetMapping("/admin/coll-question/detail")
    public CommonResult<CollQuestion> getCollQuestion(@Validated AdmCollGetQuestionForm form) {
        return CommonResult.successResponse(questionService.getCollQuestion(form));
    }

    @GetMapping("/admin/coll-question/detail-edit")
    public CommonResult<CollQuestion> getCollQuestionDetailEdit(@Validated AdmCollGetQuestionForm form) {
        return CommonResult.successResponse(questionService.getCollQuestionDetailEdit(form));
    }

    @PostMapping("/admin/coll-question/save")
    public CommonResult<CollQuestion> saveCollQuestion(@RequestBody CollQuestion collQuestion) {
        return CommonResult.successResponse(questionService.saveCollQuestion(collQuestion));
    }

    @PostMapping("/admin/coll-question/delete")
    public CommonResult<Void> deleteCollQuestion(@RequestBody BaseIdDTO dto) {
        questionService.deleteCollQuestion(dto.getId());
        return CommonResult.successResponse();
    }

    @PostMapping("/admin/coll-question/import-json")
    public CommonResult<Void> importCollQuestionJson(@RequestBody AdmCollQuestionJsonImportDTO dto) {
        questionService.importCollQuestionJson(dto);
        return CommonResult.successResponse();
    }
}
